package cloud.xiangyixiang.www.spring.boot.java.basics.controller;

import cloud.xiangyixiang.www.spring.boot.java.basics.handler.ProxyInvocationHandler;
import cloud.xiangyixiang.www.spring.boot.java.basics.service.UserService;
import cloud.xiangyixiang.www.spring.boot.java.basics.service.impl.UserServiceImpl;

/**
 * <p>
 * JAVA Dynamic Proxy 动态代理
 * </p>
 *
 * @author zhixinglu
 * @date 2023/9/7 16:29
 */
public class DynamicProxyController {

    public static void main(String[] args) {
        description();

        test1();
    }

    /**
     * 介绍详情
     */
    public static void description(){
        System.out.println("介绍详情：=========================");

        System.out.println();
    }

    private static void test1(){
        // 真实角色
        UserService userService = new UserServiceImpl();

        // 代理角色
        ProxyInvocationHandler pih = new ProxyInvocationHandler();
        // 通过调用程序处理角色来处理我们要调用的接口对象
        pih.setTarget(userService);

        UserService proxy = (UserService) pih.getProxy();
        proxy.update();
    }
}
